﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Linq;
using System.Web.UI;

using ProjectBase.Core;

namespace ProjectBase.Mvc
{
    public enum InputType
    {
        CheckBox,
        Hidden,
        Password,
        Radio,
        Text,
        File,
    }

    /// <summary>html &lt;INPUT&gt; element</summary>
    public class Input : ContentControl<ICoreModel, Input>
    {
        #region members
        #endregion members

        #region constructor
        public Input(InputType type, string cssClassName = null)
            : base(cssClassName)
        {
            SetType(type);
        }
        #endregion constructor

        #region Render
        public override void RenderControl(HtmlTextWriter writer)
        {
            writer.Write(Environment.NewLine);
            writer.WriteBeginTag(TagName);
            Attributes.Render(writer);
            writer.Write(HtmlTextWriter.SelfClosingTagEnd);
        }
        #endregion Render

        #region Set
        public virtual Input SetType(string typeName)
        {
            Type = typeName;
            return this;
        }

        protected Input SetType(InputType type)
        {
            Type = type.ToString().ToLowerInvariant();
            return this;
        }

        public virtual Input SetValue(string value)
        {
            Value = value;
            return this;
        }

        public virtual Input SetName(string name)
        {
            Name = name;
            return this;
        }

        public virtual Input SetMaxLength(int? maxLength)
        {
            if (maxLength.HasValue)
            {
                MaxLength = maxLength.Value.ToString(CultureInfo.InvariantCulture);
            }
            return this;
        }

        public virtual Input SetDisabled(bool isDisabled)
        {
            if (isDisabled)
            {
                Disabled = Attr.Disabled;
            }
            else
            {
                Attributes.Remove(Attr.Disabled);
            }
            return this;
        }

        public virtual Input SetChecked(bool isChecked)
        {
            if (isChecked)
            {
                Checked = Attr.Checked;
            }
            else
            {
                Attributes.Remove(Attr.Checked);
            }
            return this;
        }
        #endregion Set

        #region properties
        protected override string TagName
        {
            get { return Tag.Input; }
        }

        public string Type
        {
            get { return GetAttribute(Attr.Type); }
            set { SetAttribute(Attr.Type, value); }
        }

        public virtual string Checked
        {
            get { return GetAttribute(Attr.Checked); }
            set { SetAttribute(Attr.Checked, value); }
        }

        public virtual string Disabled
        {
            get { return GetAttribute(Attr.Disabled); }
            set { SetAttribute(Attr.Disabled, value); }
        }

        public virtual string Value
        {
            get { return GetAttribute(Attr.Value); }
            set { SetAttribute(Attr.Value, value); }
        }

        public virtual string Name
        {
            get { return GetAttribute(Attr.Name); }
            set { SetAttribute(Attr.Name, value); }
        }

        public virtual string MaxLength
        {
            get { return GetAttribute(Attr.MaxLength); }
            set { SetAttribute(Attr.MaxLength, value); }
        }
        #endregion properties
    }
}